package components.dialogs
{
	import UIFree.controls.uif_list;
	import UIFree.uif_component;
	
	import UIUtils.uif_util;
	
	import classes.c_blendMode;
	import classes.c_events;
	
	import components.c_checkboxLabel;
	import components.editor.c_baseElement;
	import components.propertyCtrls.c_checkboxList;
	
	import flash.display.BlendMode;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	
	import flashx.textLayout.formats.BackgroundColor;
	
	public class c_childListDialog extends c_propertyDialog {
		private var _owner	: DisplayObjectContainer;
		
		public function c_childListDialog(parent: uif_component, a_owner: DisplayObjectContainer, a_title:String='') {
			_owner = a_owner;
			super(parent, propertyList(), a_title);
		}
		
		protected function propertyList(): Array {
			return [
				{
					title	: locale.LAYERS,
					type	: c_propertyDialog.PTYPE_CHECKBOXLIST,
					value	: currentIndex,
					values	: elemList
				},{
					title	: 'Режим наложения',
					type	: c_propertyDialog.PTYPE_COMBO,
					value	: c_blendMode.list[curBlendModeIndex],
					items	: c_blendMode.list
				}
			];
		}
		
		protected function checkElement(a_element: Object): Boolean {
			return a_element is c_baseElement;
		}
		
		protected function get owner(): DisplayObjectContainer {
			return _owner;
		}
		
		protected function get currentIndex(): int {
			return -1;
		}
		
		protected function get curBlendModeIndex(): int {
			var ce: c_baseElement = curElement;
			return ce?uif_util.indexOf(c_blendMode.list, ce.blendMode, 'value'):0;
		}
		
		protected function get curElement(): c_baseElement {
			return cl.getValueEvent(c_events.GETSELECTED) as c_baseElement;
		}
		
		protected function get elemList(): Array {
			var a_items	: Array = new Array();
			for (var i: int=0; i<_owner.numChildren; i++) {
				var elem: DisplayObject = _owner.getChildAt(i) as DisplayObject;
				if (checkElement(elem)) {
				//	var typeStr: String = elem.toString();
					a_items.push({
						caption	: elem.name,// + ' ' + typeStr.substr(7, typeStr.length - 8),
						checked	: elem.visible,
						name	: elem.name
					});
				}
			};
			return a_items;
		}
		
		protected function get listLayers(): uif_list {
			return (propertyCtrls[0].control as c_checkboxList).list;
		}
		
		protected function getListItemFromName(a_name: String): c_checkboxLabel {
			var item: c_checkboxLabel;
			listLayers.area.forEach(function(a_item: c_checkboxLabel): void {
				if (a_item._data.name == a_name) item = a_item;
			}, c_checkboxLabel);			
			return item;
		}
		
		protected function updateElementList(): void {
			propertyCtrls[0].control._data = propertyList()[0];
		}
		
		protected function get valuesList(): Array {
			return values[0].values as Array;
		}	
	}
}